import request from '@/utils/request.js'
import config from '@/utils/config.js'

/**
 *获取验证码
 */
export async function getCaptcha(params) {
	let result = await uni.request({
		url: config.baseUrl + '/oauth2/v3/user/captcha',
		data: params,
		method: 'GET'
	})
	return result[1].data
	// return request.get({
	// 	url: '/oauth2/v3/user/captcha',
	// 	params
	// });
}

/**
 * 登录
 */
export function login(params) {
	return request.post({
		url:config.baseUrl + '/oauth2/v3/user/login/apply',
		params
	});
}

/**
 * 获取授权码
 */
export function authorize(loginState) {
	const params = {
		client_id: config.APP_CLIENT_ID,
		login_state: loginState
	}
	return request.post({
		url: '/oauth2/v3/authorize/apply',
		params: params
	});
}

/**
 * 获取访问token
 */
export function accessToken(authorizeCode) {
	const params = {
		authorize_code: authorizeCode,
		client_id: config.APP_CLIENT_ID,
		client_secret: config.APP_CLIENT_SECRET,
		grant_type: config.APP_GRANT_TYPE
	}
	return request.post({
		url: '/oauth2/v3/authentication/apply',
		params: params
	});
}
